use rand::{Rng};
use std::collections::HashMap;
use std::fmt::Display;

pub fn generate_random_sequence(keys_tones: &HashMap<usize, &char>) {
    let keys_tones_length = keys_tones.len();
    let mut nums: Vec<usize> = (0..keys_tones_length).collect();

    for i in 1..46 {
        for j in 0..keys_tones_length {
            let secret_number = rand::thread_rng().gen_range(0, keys_tones_length);
            nums.swap(j, secret_number);

        }
        for t in &nums {
            print!("{}", keys_tones.get(t).unwrap());
        }
        if i%3==0 {
            println!();
        }
    }
}

#[derive(Debug)]
pub enum UnExpectedError {
    IoErr(std::io::Error),
    ArgumentsNumsErr
}
impl std::error::Error for UnExpectedError {}
impl Display for UnExpectedError {
    fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
    use self::UnExpectedError::*;
        match &self {
            IoErr(ref e)=>write!(f,"IoError: {}",e),
            ArgumentsNumsErr=>write!(f,"参数数量错误")
        }
    }
}

impl From<std::io::Error> for UnExpectedError {
    fn from(io_error:std::io::Error)->Self {
        UnExpectedError::IoErr(io_error)
    }
}



